<template>
  <cu-layout :bgStyle="{ color: '#ffffff' }" :navProp="{ placeholder: true }">
    <view :class="[`${prefixCls}-user-form-container`]">
      <view class="tips-message"> 请如实填写一下信息，将作为您的入住信息保存 </view>
      <uv-form labelPosition="left" :model="formData" labelWidth="120px" ref="form">
        <uv-form-item label="通讯地址" prop="address" borderBottom>
          <uv-input v-model="formData.address" inputAlign="right" placeholder="请输入通讯地址" border="none"> </uv-input>
        </uv-form-item>
        <uv-form-item label="邮箱" prop="e_mail" borderBottom>
          <uv-input v-model="formData.e_mail" inputAlign="right" placeholder="请输入邮箱" border="none"> </uv-input>
        </uv-form-item>
        <uv-form-item label="紧急联系人" prop="emergency_name" borderBottom>
          <uv-input v-model="formData.emergency_name" inputAlign="right" placeholder="请输入紧急联系人" border="none"> </uv-input>
        </uv-form-item>
        <uv-form-item label="紧急联系人手机号" prop="emergency_tel" borderBottom>
          <uv-input v-model="formData.emergency_tel" inputAlign="right" placeholder="请输入紧急联系人手机号" border="none"> </uv-input>
        </uv-form-item>
      </uv-form>
      <view class="fixed-button" :style="{ bottom: `${safeAreaInsets}rpx` }">
        <uv-button type="primary" text="确认提交" customStyle="margin-top: 10px" @click="submit"></uv-button>
      </view>
      <uv-modal ref="modal" content="是否保存提交" :showCancelButton="true" align="center" cancelText="返回修改" confirmText="确认提交" @confirm="confirm"></uv-modal>
    </view>
  </cu-layout>
</template>

<script>
import { updateSignInfo } from '@/api/user'
import { mapActions, mapGetters } from 'vuex'

export default {
  name: 'componentName',
  components: {},
  mixins: [],
  props: {},
  data() {
    return {
      safeAreaInsets: 0,
      formData: {
        address: '',
        e_mail: '',
        emergency_name: '',
        emergency_tel: '',
      },
    }
  },
  // 侦听属性
  watch: {},
  // 计算属性
  computed: {
    ...mapGetters([]),
  },
  // 监听页面加载，该钩子被调用时data,computed,function,watch,props,slots已设置完成
  onLoad(options) {
    this.safeAreaInsets = this.$Platform.device.safeAreaInsets.bottom || 0
  },
  // 监听页面显示，页面每次出现在屏幕上都触发
  onShow() {},
  // 监听页面初次渲染完成，此时组件已挂载完成
  onReady() {},
  // 下拉刷新
  onPullDownRefresh() {},
  // 加载更多
  onReachBottom() {},

  created() {},
  mounted() {},
  destroyed() {},
  methods: {
    ...mapActions([]),
    async confirm() {
      const { data, errcode } = await updateSignInfo({ ...this.formData })
      console.log('errcode', errcode)
      if (errcode === 0) {
        uni.$uv.toast('操作成功')
        uni.redirectTo({ url: '/pages/user/user-info' })
        // this.$ROUTE.go()
      }
    },
    submit() {
      this.$refs.modal.open()
    },
  },
}
</script>

<style lang="scss" scoped>
page {
  background: white !important;
}
.#{prefixCls('user-form-container')} {
  position: relative;
  background: white;
  box-sizing: border-box;
  overflow: hidden;
  padding: 15px;
  .tips-message {
    color: $uv-primary;
    border: 1px solid $uv-primary;
    padding: 15px;
    border-radius: 8rpx;
    font-size: 12px;
    text-align: center;
    margin-bottom: 20px;
    background: #ffe5d8;
  }
  .fixed-button {
    position: fixed;
    left: 0;
    z-index: 2;
    width: 100%;
    background: linear-gradient(to bottom, white, #f5f5f5);
    padding: 20rpx 30rpx;
    box-sizing: border-box;
    border-top: 1px solid #f1f1f1;
    display: flex;
    ::v-deep .uv-button-wrapper {
      flex: 1;
      margin: 0 15px;
    }
  }
}
</style>
